package com.guigu.eduservice.controller;

import com.guigu.common.utils.R;
import com.guigu.eduservice.entity.User;
import com.guigu.eduservice.service.UserService;
import com.guigu.eduservice.utils.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.time.LocalDateTime;

/**
 * <p>
 * 用户表（平台买卖双方用户） 前端控制器
 * </p>
 *
 * @author Xiaosong
 * @since 2025-10-20
 */
@RestController
@RequestMapping("/advertisement/user")
public class UserController {
    @Autowired
    private UserService userService;
    //根据userId查询
    @GetMapping("/{userId}")
    public R SelectUserById(@PathVariable Long userId){
        User user=userService.getById(userId);
        return R.ok().data("user",user);
    }
    //添加用户
    @PostMapping("/addUser")
    public R addUser(@RequestBody User user){
        //密码加密
        user.setPassword(MD5.encrypt(user.getPassword()));
        user.setStatus(1);
        user.setUserType(0);
        System.out.println("useruser"+user);
        userService.save(user);
        return R.ok();
    }

}
